<?php
if (isset($_GET['id']) && !empty($_GET['id'])) {
  $id = $_GET['id'];
  // 查询要删除的留言记录的用户名
  $sql = 'select user_name from messages where id=?';
  $data = query($sql, [$id]);
  if (count($data) > 0) {
     $user = $data[0];
     $userName = $user['user_name'];
     // 确保要删除的留言记录的用户名跟当前登录用户一致
     if ($userName == $_SESSION['user']['user_name']) {
        $sql = 'delete from messages where id=?';
        execute($sql, [$id]);
     }
  }
}

header('Location:' . url('index'));
